home *** CD-ROM | disk | FTP | other *** search
/ TeX 1995 July / TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO / dviware / xdvi-dos / src / vf.c < prev    next >
C/C++ Source or Header  |  1992-10-21  |  3KB  |  124 lines

  1. #include "xdvi.h"
  2. #include "dvi.h"
  3.  
  4. #ifndef    X_NOT_STDC_ENV
  5. #include <stdlib.h>
  6. #endif
  7.  
  8. /***
  9.  ***    VF font reading routines.
  10.  ***    Public routine is read_index---because virtual characters are presumed
  11.  ***    to be short, we read the whole virtual font in at once, instead of
  12.  ***    faulting in characters as needed.
  13.  ***/
  14.  
  15. #define    LONG_CHAR    242
  16.  
  17. /*
  18.  *    These are parameters which determine whether macros are combined for
  19.  *    storage allocation purposes.  Small macros ( <= VF_PARM_1 bytes) are
  20.  *    combined into chunks of size VF_PARM_2.
  21.  */
  22.  
  23. #ifndef    VF_PARM_1
  24. #define    VF_PARM_1    20
  25. #endif
  26. #ifndef    VF_PARM_2
  27. #define    VF_PARM_2    256
  28. #endif
  29.  
  30. /*
  31.  *    The main routine
  32.  */
  33.  
  34. void
  35. read_VF_index(fontp)
  36.     register struct font *fontp;
  37. {
  38.     FILE    *VF_file = fontp->file;
  39.     ubyte    cmnd;
  40.     ubyte    *avail, *availend;    /* available space for macros */
  41.  
  42.     fontp->read_char = NULL;
  43.     fontp->flags |= FONT_VIRTUAL;
  44.     fontp->set_char_p = set_vf_char;
  45.     if (debug & DBG_PK)
  46.         Printf("Reading VF pixel file %s\n", fontp->filename);
  47. /*
  48.  *    Read preamble.
  49.  */
  50.     Fseek(VF_file, (long) one(VF_file), 1);    /* skip comment */
  51.     (void) four(VF_file);        /* skip checksum */
  52.     (void) four(VF_file);        /* skip design size */
  53. /*
  54.  *    Read the fonts.
  55.  */
  56.     fontp->vf_chain = NULL;
  57.     fontp->first_font = NULL;
  58.     while ((cmnd = one(VF_file)) >= FNTDEF1 && cmnd <= FNTDEF4) {
  59.         define_font(VF_file, cmnd, fontp, &fontp->vf_chain);
  60.         if (fontp->first_font == NULL)
  61.         fontp->first_font = fontp->vf_chain->fontp;
  62.     }
  63. /*
  64.  *    Prepare macro array.
  65.  */
  66.     fontp->macro = (struct macro *) xmalloc(256 * sizeof(struct macro),
  67.         "macro array");
  68.     bzero((char *) fontp->macro, 256 * sizeof(struct macro));
  69. /*
  70.  *    Read macros.
  71.  */
  72.     avail = availend = NULL;
  73.     for (; cmnd <= LONG_CHAR; cmnd = one(VF_file)) {
  74.         register struct macro *m;
  75.         int len;
  76.         unsigned long cc;
  77.         long width;
  78.  
  79.         if (cmnd == LONG_CHAR) {    /* long form packet */
  80.         len = four(VF_file);
  81.         cc = four(VF_file);
  82.         width = four(VF_file);
  83.         if (cc >= 256) {
  84.             Fprintf(stderr,
  85.             "Virtual character %lu in font %s ignored.\n",
  86.             cc, fontp->fontname);
  87.             Fseek(VF_file, (long) len, 1);
  88.             continue;
  89.         }
  90.         }
  91.         else {    /* short form packet */
  92.         len = cmnd;
  93.         cc = one(VF_file);
  94.         width = num(VF_file, 3);
  95.         }
  96.         m = &fontp->macro[cc];
  97.         m->dvi_adv = width * fontp->dimconv;
  98.         if (len > 0) {
  99.         if (len <= availend - avail) {
  100.             m->pos = avail;
  101.             avail += len;
  102.         }
  103.         else {
  104.             m->free_me = True;
  105.             if (len <= VF_PARM_1) {
  106.             m->pos = avail = (ubyte *) xmalloc(VF_PARM_2,
  107.                 "macro array");
  108.             availend = avail + VF_PARM_2;
  109.             avail += len;
  110.             }
  111.             else m->pos = (ubyte *) xmalloc((unsigned) len,
  112.             "macro array");
  113.         }
  114.         Fread((char *) m->pos, 1, len, VF_file);
  115.         m->end = m->pos + len;
  116.         }
  117.         if (debug & DBG_PK)
  118.         Printf("Read VF macro for character %lu; dy = %ld, length = %d\n",
  119.             cc, m->dvi_adv, len);
  120.     }
  121.     if (cmnd != POST)
  122.         oops("Wrong command byte found in VF macro list:  %d", cmnd);
  123. }
  124.